package edu.ycu.aladdin.collector.service.weibo;

import com.alibaba.dubbo.config.annotation.Service;
import edu.ycu.aladdin.collector.CrawlerConfigPool;
import edu.ycu.aladdin.collector.api.CrawlerService;
import edu.ycu.aladdin.collector.api.entity.weibo.WeiBoDataTaskQueue;
import edu.ycu.aladdin.common.interfaces.ProcessAble;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import us.codecraft.webmagic.Page;

/**
 * TODO 微博用户微博页数据
 * @author <a href="mailto:wangruihuano@gmail.com">王瑞环</a>
 * @since 2019-04-07 23:22
 */
@org.springframework.stereotype.Service
@Service(interfaceClass = CrawlerService.class, timeout = 10000, group = "weibo-data-crawler-service")
public class WeiBoDataCrawlerService extends BaseCrawlerWebmagicService<WeiBoDataTaskQueue> {

    @Value("${weibo.template.page-data-url}")
    private String templateUrl;

    @Autowired
    public WeiBoDataCrawlerService(CrawlerConfigPool crawlerConfigPool) {
        super(crawlerConfigPool);
    }

    @Override
    protected void storage(WeiBoDataTaskQueue task) {

    }

    @Override
    protected void processException(WeiBoDataTaskQueue task, Exception e) {

    }

    @Override
    protected String initUrl(WeiBoDataTaskQueue task) {

        // TODO 待确定 containerid
        return "";
    }

    @Override
    protected ProcessAble<Page> doProcess(WeiBoDataTaskQueue task) {
        return null;
    }


    private String replateTemplateUrl(String page, String containerid, String uid) {
        return templateUrl.replace("{{uid}}", uid)
                .replace("{{containerid}}", containerid)
                .replace("{{page}}", page);
    }
}
